<!doctype html>
<html lang="en" class="fixed">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <title>用户管理</title>
    <link rel="apple-touch-icon" sizes="120x120" href="favicon/apple-icon-120x120.png">
    <link rel="icon" type="image/png" sizes="192x192" href="favicon/android-icon-192x192.png">
    <link rel="icon" type="image/png" sizes="32x32" href="favicon/favicon-32x32.png">
    <link rel="icon" type="image/png" sizes="16x16" href="favicon/favicon-16x16.png">
    <link rel="stylesheet" type="text/css"
          href="<?php xcho(loadSource('/assets/plugins/bootstrap/css/bootstrap.min.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/plugins/animate.css/animate.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/plugins/font-awesome/css/font-awesome.css')) ?>">
    <link rel="stylesheet"
          href="<?php xcho(loadSource('/assets/plugins/data-table/media/css/dataTables.bootstrap.min.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/plugins/ztree/css/zTreeStyle/zTreeStyle.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/app/css/style.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/plugins/layui/css/layui.css')) ?>" media="all">
    <link rel="stylesheet" href="<?php xcho(loadSource('/app/css/app.css')) ?>">
    <link rel="stylesheet" href="<?php xcho(loadSource('/assets/css/new_main.css')) ?>">
    <style>
        .pagination {
            margin: 0;
        }

        .updates .modal-content {
            padding: 20px;
        }

        .updates .modal-content .dialog-select {
            width: 100%;
            text-align: left;
        }

        .updates .modal-content .dialog-select:hover {

        }

        .updates .modal-content .dialog-select span {
            float: right;
            margin-top: 2px;
            font-size: 8px;
            color: #999;
        }

        .updates .modal-content ul {
            width: 80%;
            top: 60px;
            left: 40px;
        }

        .updates .modal-content input {
            width: 100%;
            border-radius: 5px;
            border: 0;
            border: 1px #ccc solid;
            outline: none;
            text-indent: 10px;
        }
    </style>
</head>

<body><?php include_once TPL_PATH . 'public/nav.phtml'; ?>

<div class="wrap">
    <div class="page-body" style="padding: 0">
        <div class="content" style="margin: 0;background: #ececec">
            <div class="row">
                <form method="get">
                    <div class="input-group col-md-4">
                        <input type="text" class="form-control" name="keyword" value="<?php xcho($keyword)  ?>" autocomplete="off" placeholder="搜索用户名" />
                        <div class="btns-group">
                            <input type="submit" class="btn btn-primary edit" value="确定" />
                        </div>
                    </div>

                </form>
                <div class="col-sm-12">
                    <div class="panel">
                        <div class="panel-header">

                            <div class="from-top-right">
                                <button class="layui-btn layui-btn-small layui-btn-warm" id="change_levels"><i class="layui-icon">&#xe642;</i> 批量修改</button>
                                <button class="layui-btn layui-btn-small " id="add"><i class="layui-icon">&#xe608;</i> 添加</button>
                            </div>
                            <div class="top_pages" style="display: none">
                                <ul>
                                    <?php xchoHtml($page->render()) ?>
                                </ul>
                            </div>
                        </div>
                        <div class="panel-content">

                            <div class="table-responsive layui-form">
                                <table class="layui-table" lay-filter="demo">
                                    <thead>
                                    <tr>
                                        <th>
                                            <div id="checkAll" ><input  lay-filter="allChoose" type="checkbox" lay-skin="primary" name="checkAll"></div>
                                        </th>
                                        <th>姓名</th>
                                        <th>用户名</th>
                                        <th>角色</th>
                                        <th>分组</th>
                                        <th>状态</th>
                                        <th>手机号</th>
                                        <th>邮箱</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <?php foreach ($list as $k => $v) { ?>
                                        <tr>
                                            <td>
                                               <input  lay-filter="itemChoose" value="<?php xcho($v['id']) ?>" type="checkbox" name="ck" lay-skin="primary">
                                            </td>
                                            <td>
                                                <?php xcho($v['full_name']) ?></td>

                                            <td><?php xcho($v['user_name']) ?></td>
                                            <td><?php xcho($v['role_name']) ?></td>
                                            <td><?php xcho($v['group_name']) ?></td>
                                            <td><?php xcho($v['status_value']) ?></td>
                                            <td><?php xcho($v['cellphone']) ?></td>
                                            <td><?php xcho($v['email']) ?></td>
                                            <td>
                                                <button data-cn_id="<?php xcho($v['id']) ?>" type="button"
                                                        class="btn btn-sub updatepass">
                                                    修改密码
                                                </button>
                                                <button data-cn_id="<?php xcho($v['id']) ?>" type="button"
                                                        class="btn btn-primary edit"
                                                        user_id="<?php xcho($v['id']) ?>"><a
                                                            href="<?php xcho($edit_url) ?>?user_id=<?php xcho($v['id']) ?>">编辑</a>
                                                </button>
                                                <button data-cn_id="<?php xcho($v['id']) ?>" type="button"
                                                        class="btn btn-danger delete">删除
                                                </button>
                                                <?php if($v['status_value']=='激活'){ ?>
                                                <button data-cn_id="<?php xcho($v['id']) ?>"
                                                        data-user_name="<?php xcho($v['user_name']) ?>" type="button"
                                                        class="btn btn-primary login">模拟登陆
                                                </button>
                                                <?php } ?>
                                            </td>
                                        </tr>
                                    <?php } ?>

                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="panel-footer">
                            <div class="top_pages bottom_pages">
                                <ul>
                                    <?php xchoHtml($page->render()) ?>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <a href="#" class="scroll-to-top"><i class="fa fa-angle-double-up"></i></a>
    </div>
</div>
<div class="modal fade" id="info-modal-update" tabindex="-1" role="dialog" aria-labelledby="modal-info-label">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header state modal-info">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="modal-info-label"><i class="fa fa-info"></i></h4>
            </div>
            <div class="modal-body" style="min-height: 150px;">
                <div class="col-xs-12">
                    <label class="col-sm-3 control-label" style="line-height: 34px;text-align: right">新密码:</label>
                    <div class="col-sm-9">
                        <input class="form-control" name="new_password" type="text" placeholder="新密码">
                    </div>
                </div>
                <div class="col-xs-12">
                    <label class="col-sm-3 control-label" style="line-height: 34px;text-align: right">确认密码:</label>
                    <div class="col-sm-9">
                        <input class="form-control" name="confirm_password" type="text" placeholder="确认密码">
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" id="sureGroup" data-dismiss="modal">确定</button>
                <button type="button" class="btn btn-default" id="returnGroup" data-dismiss="modal">返回</button>
            </div>
        </div>
    </div>
</div>
<div id="modalbox"></div>
<div class="modal fade" id="info-modal-group" tabindex="-1" role="dialog" aria-labelledby="modal-info-label">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header state modal-info">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="modal-info-label"><i class="fa fa-info"></i></h4>
            </div>
            <div class="modal-body" style="min-height: 150px;">
                <ul class="ztree" id="group"></ul>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" id="sure_group" data-dismiss="modal">确定</button>
                <button type="button" class="btn btn-default" id="return_group" data-dismiss="modal">返回</button>
            </div>
        </div>
    </div>
</div>
<input type="hidden" name="save_user" value="<?php xcho($save_user) ?>"/>
<input type="hidden" name="add_url" value="<?php xcho($add_url) ?>"/>
<input type="hidden" name="edit_url" value="<?php xcho($edit_url) ?>"/>
<input type="hidden" name="del_user" value="<?php xcho($del_user) ?>"/>
<input type="hidden" name="analog_login" value="<?php xcho($analog_login) ?>"/>
<input type="hidden" name="medit_pwd" value="<?php xcho($medit_pwd) ?>"/>
<input type="hidden" name="batch_userinfo" value="<?php xcho($batch_userinfo) ?>"/>
<input type="hidden" name="role_list" value="<?php xcho($roleList) ?>"/>
<input type="hidden" name="group_list" value="<?php xcho($groupList) ?>"/>
<script src="<?php xcho(loadSource('/assets/plugins/jquery/jquery.min.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets/plugins/bootstrap/js/bootstrap.min.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets/plugins/data-table/media/js/jquery.dataTables.min.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets/plugins/data-table/media/js/dataTables.bootstrap.min.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets/plugins/layui/layui.all.js')) ?>" charset="utf-8"></script>
<script
        src="<?php xcho(loadSource('/assets/plugins/data-table/extensions/Responsive/js/dataTables.responsive.min.js')) ?>"></script>
<script
        src="<?php xcho(loadSource('/assets/plugins/data-table/extensions/Responsive/js/responsive.bootstrap.min.js')) ?>"></script>
<script src="<?php xcho(loadSource('/assets//plugins/ztree/js/jquery.ztree.core.js')) ?>"></script>
<script type="text/javascript"
        src="<?php xcho(loadSource('/assets//plugins/ztree/js/jquery.ztree.excheck.js')) ?>"></script>
<script type="text/javascript"
        src="<?php xcho(loadSource('/assets//plugins/ztree/js/jquery.ztree.exedit.js')) ?>"></script>
<script>
    $(function () {


        "use strict";
        layui.use('table', function(){
            var table = layui.table;
            var $ = layui.jquery,
                form = layui.form;
            form.on('checkbox(allChoose)', function(data){
                var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
                child.each(function(index, item){
                    item.checked = data.elem.checked;
                });
                form.render('checkbox');
            });
            form.on('checkbox(itemChoose)',function(data){
                var sib = $(data.elem).parents('table').find('tbody input[type="checkbox"]:checked').length;
                var total = $(data.elem).parents('table').find('tbody input[type="checkbox"]').length;
                if(sib == total){
                    $(data.elem).parents('table').find('thead input[type="checkbox"]').prop("checked",true);
                    form.render();
                }else{
                    $(data.elem).parents('table').find('thead input[type="checkbox"]').prop("checked",false);
                    form.render();
                }
            });
            $("#add").on("click", function () {
                var add_url = $("input[name='add_url']").val();
//            console.log(add_url)
//            window.parent.addParentTab({href:add_url,title:'消息列表'})
                location.href = add_url;
            });


//        $(".edit").on("click", function () {
//            var edit_url = $("input[name='edit_url']").val();
//            var user_id=$(this).attr('user_id');
//
//            console.log(edit_url)
////            window.parent.addParentTab({href:add_url,title:'消息列表'})
//            location.href = edit_url;
//        });
            $(".delete").on("click", function () {
                var cn_id = $(this).attr("data-cn_id");
                $.ajax({
                    url: $("input[name='del_user']").val(),
                    data: {
                        id: cn_id
                    },
                    type: 'post',
                    dataType: 'json',
                    success: function (data) {
                        console.log(data)
                        if (data.success == 1) {
                            layer.alert("删除成功!", {
                                skin: 'layui-layer-molv'
                            },function () {
                                location.reload();
                            })
                        } else {
                            layer.alert(data.msg, {
                                skin: 'layui-layer-molv'
                            },function () {
                                location.reload();
                            })
                        }
                    },
                    complete: function () {
                    },
                    error: function () {

                    }
                });
            })
            $(".login").on("click", function () {
                var user_name = $(this).attr("data-user_name");
                var user_id= $(this).attr("data-cn_id");
                $.ajax({
                    url: $("input[name='analog_login']").val(),
                    data: {
                        user_name: user_name,
                        user_id:user_id,
                    },
                    type: 'post',
                    dataType: 'json',
                    success: function (data) {
                        console.log(data)
                        if (data.success == 1) {

                            parent.location.href = data.url + '?user_name=' + user_name;

                        } else {
                            alert(data.msg)
                        }
                    },
                    complete: function () {
                    },
                    error: function () {

                    }
                });
            })

            $(".updatepass").on("click", function () {
                var cn_id = $(this).attr("data-cn_id");
                console.log(cn_id)
                var modal = '<div class="modal fade" id="info-modal-pass" tabindex="-1" role="dialog" aria-labelledby="modal-info-label">' +
                    ' <div class="modal-dialog" role="document">' +
                    ' <div class="modal-content">' +
                    '<div class="modal-header state modal-info">' +
                    '<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>' +
                    '</button>' +
                    '<h4 class="modal-title" id="modal-info-label"><i class="fa fa-info"></i></h4>' +
                    '</div>' +
                    ' <div class="modal-body" style="min-height: 150px;">' +
                    '<div class="col-xs-12">' +
                    ' <label class="col-sm-3 control-label" style="line-height: 34px;text-align: right">新密码:</label>' +
                    '<div class="col-sm-9">' +
                    '<input class="form-control" name="new_password" type="text" placeholder="新密码">' +
                    '</div>' +
                    '</div>' +
                    ' <div class="col-xs-12">' +
                    ' <label class="col-sm-3 control-label" style="line-height: 34px;text-align: right">确认密码:</label>' +
                    ' <div class="col-sm-9">' +
                    '<input class="form-control" name="confirm_password" type="text" placeholder="确认密码">' +
                    ' </div>' +
                    ' </div>' +
                    ' </div>' +
                    '<div class="modal-footer">' +
                    '<button type="button" class="btn btn-info" id="surepass" data-dismiss="modal">确定</button>' +
                    '<button type="button" class="btn btn-default" id="returnGroup" data-dismiss="modal">返回</button>' +
                    '</div>' +
                    '</div>' +
                    '</div>' +
                    '</div>';
                $("#modalbox").html("").html(modal);
                $('#info-modal-pass').modal({
                    keyboard: false,
                    backdrop: false
                });
                $('#info-modal-pass').on('shown.bs.modal', function (e) {
                    // 关键代码，如没将modal设置为 block，则$modala_dialog.height() 为零
                    $(this).css('display', 'block');
                    $(this).find('.modal-dialog').css({
                        'margin-top': "100px"
                    });
                });
                $("#surepass").on("click", function () {
                    console.log($("#info-modal-pass input[name='new_password']").val())
                    $.ajax({
                        url: $("input[name='medit_pwd']").val(),
                        data: {
                            id: cn_id,
                            new_password: $("#info-modal-pass input[name='new_password']").val(),
                            confirm_password: $("#info-modal-pass input[name='confirm_password']").val()
                        },
                        type: 'post',
                        dataType: 'json',
                        success: function (data) {
                            console.log(data)
                            if (data.success == 1) {
                                layer.alert("修改成功")
                            } else {
                                layer.alert(data.msg)
                            }
                        },
                        complete: function () {
                        },
                        error: function () {

                        }
                    });
                })

            });
            $("#change_levels").on("click", function () {
                var ids = [];
                $('input[name="ck"]:checked').each(function () {
                    ids.push($(this).val());
                });
                console.info(ids);
                var param = {};
                if (ids.length == 0) {
                    layer.alert("至少选择一项");
                } else {
                    param.ids = ids;
                    var $select_modal = '<div class="modal fade bs-example-modal-sm updates" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">' +
                        '<div class="modal-dialog modal-sm" role="document">' +
                        '<div class="modal-content">' +
                        '<button class="btn btn-default dropdown-toggle dialog-select" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">' +
                        '选择条件' +
                        '<span class="glyphicon glyphicon-menu-down"></span>' +
                        '</button>' +
                        '<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">' +
                        '<li><a href="#">分组</a></li>' +
                        '<li><a href="#">角色</a></li>' +
                        '<li><a href="#">状态</a></li>' +
                        '</ul>' +
                        '<div class="user_data_area"></div>' +
                        '<div class="modal-footer">' +
                        '<button type="button" class="btn btn-info btn-xs" id="save2" data-dismiss="modal">保存</button>' +
                        '<button type="button" class="btn btn-default btn-xs" id="return2" data-dismiss="modal">返回</button>' +
                        '</div>' +
                        '</div>' +
                        '</div>' +
                        '</div>';
                    $("#modalbox").html($select_modal);
                    $(".updates").modal({
                        keyboard: false,
                        backdrop: false
                    });
                    $(".updates").on('shown.bs.modal', function (e) {
                        // 关键代码，如没将modal设置为 block，则$modala_dialog.height() 为零
                        $(this).css('display', 'block');
                        $(this).find('.modal-dialog').css({
                            'margin-top': "100px"
                        });
                        $(".dropdown-menu>li").click(function () {
                            var textD = $(this).find("a").text();
                            $(".dialog-select").html(textD + '<span class="glyphicon glyphicon-menu-down"></span>');
                            console.log(ids);
                            if (textD == "角色") {
                                $.ajax({
                                    url: $("input[name='role_list']").val(),
                                    type: 'post',
                                    dataType: 'json',
                                    success: function (data) {
                                        console.log(data)
                                    },
                                    complete: function () {
                                    },
                                    error: function () {

                                    }
                                });
                                $("input[name='edit_data']").focus(function () {

                                })
                            } else if (textD == "状态") {
                                $(".user_data_area").html("").html('<select id="select_id" class="form-control">' +
                                    '<option value="disable" selected>禁用</option>' +
                                    '<option value="active" >激活</option>' +
                                    '</select>');
                                param.status_value = $("#select_id").val();
                                $("#select_id").change(function () {
                                    console.log($("#select_id").find("option:selected").text())
                                    param.status_value = $("#select_id").val();
                                });

                            } else if (textD == "分组") {
                                $(".user_data_area").html("").html('<input name="edit_data" type="text">');
                                var group_list = getListData($("input[name='group_list']").val());
                                console.log(group_list)
                                var settingGroup = {
                                    view: {
                                        selectedMulti: false
                                    },
                                    edit: {
                                        enable: false
                                    },
                                    data: {
                                        keep: {
                                            parent: true,
                                            leaf: true
                                        },
                                        simpleData: {
                                            enable: true
                                        }
                                    }
                                };
                                var zNodes = group_list;
                                console.log(zNodes)
                                $.each(zNodes, function (i, item) {
                                    item.isParent = true;
                                });
                                $.fn.zTree.init($("#group"), settingGroup, zNodes);
                                $("input[name='edit_data']").focus(function (e) {
//                                        console.log(e)
                                    $('#info-modal-group').modal({
                                        keyboard: false,
                                        backdrop: false
                                    });
                                    $('#info-modal-group').on('shown.bs.modal', function (e) {
                                        // 关键代码，如没将modal设置为 block，则$modala_dialog.height() 为零
                                        $(this).css('display', 'block');
                                        $(this).find('.modal-dialog').css({
                                            'margin-top': "100px"
                                        });
                                        $("#sure_group").on("click", function () {
                                            var zTree = $.fn.zTree.getZTreeObj("group"),
                                                nodes = zTree.getSelectedNodes(),
                                                treeNode = nodes[0];
                                            console.log(treeNode);
                                            if (nodes.length == 0) {
                                                layer.alert("请先选择一个节点", {
                                                    skin: 'layui-layer-molv'
                                                });
                                                return;
                                            }
                                            $("input[name='edit_data']").val(treeNode.name).attr("data-tid", treeNode.id);
                                            console.log("asdasdas=" + $("input[name='edit_data']").attr("data-tid"))
                                            param.group_id = $("input[name='edit_data']").attr("data-tid")
                                        });
                                    });
                                    $('#info-modal-group').on('hide.bs.modal', function (e) {
                                        $("#sure_group").unbind("click")
                                    });
                                });
                            }
                        })
                    });
                    $("#save2").on("click", function () {
                        submitData($("input[name='batch_userinfo']").val(), param);
                    });
                }
            });
            function submitData(url, param) {
                $.ajax({
                    url: url,
                    type: 'post',
                    data: param,
                    dataType: 'json',
                    success: function (data) {
                        console.log(data)
                        if (data.success == 1) {
                            layer.alert("保存成功", {
                                skin: 'layui-layer-molv'
                            }, function () {
                                location.reload();
                            })
                        } else {
                            layer.alert("保存失败", {
                                skin: 'layui-layer-molv'
                            }, function () {
                                location.reload();
                            })
                        }
                    },
                    complete: function () {

                    },
                    error: function () {

                    }
                });
            }

            function getListData(url) {
                var data_list;
                $.ajax({
                    url: url,
                    type: 'post',
                    async: false,
                    dataType: 'json',
                    success: function (data) {
                        console.log(data)
                        if (data.success == 1) {
                            data_list = data.data_list;
                        } else {
                        }
                    },
                    complete: function () {
                    },
                    error: function () {

                    }
                });
                return data_list;
            }

        });
        //TABLE


    });
</script>
    <?php include_once TPL_PATH . 'public/foot_script.phtml'; ?>

<button id="top" style="height: 50px;width: 50px;"></button></body>

</html>
